<?php
/**
 *投诉
 */
class ComplaintController extends AdminBaseController {
	public function lists (){
		$complaint = HttpServerManager::getComplaintServer();
		$data = $complaint->pagingBySearch($_GET);
		$type = Common::_t('complaint_type');
		$data['typeOptions'] = page_modifier_options($type,common::getGetStrValue('type'));
		$data['type'] = $type;
		$userDao= HttpDaoManager::getUserDao();
		$teacherDao = HttpDaoManager::getTeacherDao();
		foreach ($data['list'] as $k=>$v){
			$user = $userDao->get($data['list'][$k]['user_id']);
			$data['list'][$k]['user_name'] = $user['english_name'];
			if(isset($v['teacher_id'])&&$v['teacher_id']>0){
				$teacher = $teacherDao->get($v['teacher_id']);
				$data['list'][$k]['teacher_name'] = $teacher['name'];
			}
		}
		$complaint_status = Common::_t('complaint_status');
		$data['statusOptions'] = page_modifier_options($complaint_status,common::getGetStrValue('status'));
		$data['complaint_status'] = $complaint_status;
		
		return $data;
	}
	public function add(){
		$data = array();
		if (!empty($_GET['id'])){
			$data = HttpDaoManager::getComplaintDao()->get($_GET['id']);
			$user =  HttpDaoManager::getUserDao()->get($data['user_id']);
			$data['user']= $user;
			if($data['order_type']!=""){
				if($data['order_type'] == COMPLAINT_TYPE_ORDER_TYPE){
					$order = HttpDaoManager::getOrderDao()->get($data['target_id']);
					$data['target'] = $order['order_no'];
				}
				if($data['order_type'] == COMPLAINT_TYPE_BOOKORDER_TYPE){
					$order = HttpDaoManager::getBookCourseDao()->get($data['target_id']);
					$data['target'] = $order['book_no'];
				}
			}
		}
		
		$type = Common::_t('complaint_type');
		$data['typeOptions'] = page_modifier_options($type,common::getStrValue($data, 'type'));
		
		
		$complaint_order_type = Common::_t('complaint_order_type');
		$data['comlaintTypeOptions'] = page_modifier_options($complaint_order_type,common::getStrValue($data, 'order_type'));
		
		$complaint_status = Common::_t('complaint_status');
		$data['statusOptions'] = page_modifier_options($complaint_status,common::getStrValue($data, 'status'));
		$data['id'] = Common::getGetStrValue('id');
		
		$follow_employees = HttpDaoManager::getEmployeesDao()->searchList();
		$follow_employees_pairs=array();
		foreach ($follow_employees as $v){
			$follow_employees_pairs[$v['id']] = $v['name'];
		}		
		$data['trackPeopleOptions'] = page_modifier_options($follow_employees_pairs,common::getStrValue($data, 'employee_id'));		
		
		$data['departmentList'] = Common::_t('department');
		$employees = array();
		$employeesDao = HttpDaoManager::getEmployeesDao();
		foreach ($data['departmentList'] as $k=>$v){
			$employees[$k] = $employeesDao->getListByDepartment($k);
		}		

		$data['employees'] = $employees;
		$data['teacher'] = HttpDaoManager::getTeacherDao()->searchList();	

		return $data;
	}
	public function delete(){
		HttpServerManager::getCourseServer()->deleteBatchByid($_GET['id']);
		ClassManager::getToos()->msgbox("删除成功");
	}
	
	public function subAdd(){
		$data=$_POST;
		$data['user_id'] = $_POST['user_id'];
		$data['target_id'] = $_POST['target_id'];
		$data['type']=$_POST['type'];
		$data['order_type']=$_POST['order_type'];
		$data['dept_id'] = $_POST['dept_id'];
		$data['employee_id'] = $_POST['employee_id'];
		$data['teacher_id'] = $_POST['teacher_id'];
		$data['content'] = $_POST['content'];
		$data['status'] = $_POST['status'];
		
		if($data['type']==COMPLAINT_TYPE_CUSTOMERSERVICE){
			$data['teacher_id'] =0;
		}
		HttpServerManager::getComplaintServer()->complaint($data);
		ClassManager::getToos()->msgbox("添加成功");
	}
	
	public function subUpdate(){
		$data=$_POST;
		$data['id']=$_POST['id'];
		$data['user_id'] = $_POST['user_id'];
		$data['target_id'] = $_POST['target_id'];
		$data['type']=$_POST['type'];
		$data['order_type']=$_POST['order_type'];
		$data['dept_id'] = $_POST['dept_id'];
		$data['employee_id'] = $_POST['employee_id'];
		$data['teacher_id'] = $_POST['teacher_id'];
		$data['content'] = $_POST['content'];
		$data['status'] = $_POST['status'];
		
		if($data['type']==COMPLAINT_TYPE_CUSTOMERSERVICE){
			$data['teacher_id'] =0;
		}
		
		HttpServerManager::getComplaintServer()->complaintUpdate($data);
		ClassManager::getToos()->msgbox("更新成功");
	}
}
?>